package com.isesol.orm.jpa;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.springframework.data.jpa.domain.support.AuditingEntityListener;

@MappedSuperclass
@EntityListeners({AuditingEntityListener.class})
public class BaseIdEntity<EIT> implements Serializable {

    protected EIT id;
    protected String jqId;
    protected Map<String, Object> properties = new HashMap<>();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public EIT getId() {
        return id;
    }

    public void setId(EIT id) {
        this.id = id;
    }

    public void setJqId(String jqId) {
        this.jqId = jqId;
    }

    /**
     * 获取附加属性
     *
     * @return
     */
    @Transient
    public Map<String, Object> getProperties() {
        return properties;
    }

    @Transient
    public Object getProperty(String key) {
        return properties.get(key);
    }

    public void addProperty(String key, Object value) {
        properties.put(key, value);
    }

}
